

"""
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

driver = webdriver.Chrome()
driver.maximize_window()
driver.get('https://qzone.qq.com/')

# 切换iframe: 1、有id 和name 直接切换
driver.switch_to.frame("login_frame")

# 点击密码登录link --在iframe子页面里 需要先进行iframe切换
driver.find_element(By.ID,'switcher_plogin').click()
driver.find_element(By.ID,'u').send_keys("test123")
driver.find_element(By.ID,'p').send_keys("lemon666")

sleep(2)
# driver.close()
"""


# 练习

from selenium import webdriver
from selenium.webdriver.common.by import By
import time
driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://qzone.qq.com/")


driver.switch_to.frame("login_frame")
driver.find_element(By.XPATH,"//a[@id='switcher_plogin']").click()
driver.find_element(By.XPATH,"//input[@id='u']").send_keys("306775891")
driver.find_element(By.XPATH,"//input[@id='p']").send_keys("liwei521314")
driver.find_element(By.XPATH,"//input[@class='btn']").click()

time.sleep(5)

# 总结
# 1、先查看页面是否有子页面嵌套 frame  如果有id\name  直接切换页面 然后在元素定位
# driver.switch_to.frame("login_frame")